//读条之前加载loading资源组的进度界面
class Load extends eui.Group implements RES.PromiseTaskReporter {
    public constructor() {
        super();
        this.addEventListener(egret.Event.ADDED_TO_STAGE, this.createView, this);
        this.addEventListener(egret.Event.REMOVED_FROM_STAGE, this.destroy, this);
        egret.MainContext.instance.stage.addEventListener(egret.Event.RESIZE, this.modifyBody, this)
    }
    private pg: eui.Image;
    private pgBg: eui.Image;
    private pgBg2: eui.Image;
    private pgBar: eui.Image;
    private textField: eui.Label;
    private w: number = 0;
    private h: number = 0;

    private createView(): void {
        this.w = egret.MainContext.instance.stage.stageWidth;
        this.h = egret.MainContext.instance.stage.stageHeight;
        this.width = egret.MainContext.instance.stage.stageWidth
        this.height = egret.MainContext.instance.stage.stageHeight
        this.pg = new eui.Image("resource/images/loading/login_bg.jpg");
        this.pg.left = 0
        this.pg.right = 0
        this.pg.top = 0
        this.pg.bottom = 0
        this.addChild(this.pg);
        this.pg.addEventListener(egret.Event.COMPLETE, closeLoad, this)

        this.pgBg2 = new eui.Image("resource/images/loading/loadingBg.png");
        this.pgBg2.horizontalCenter = 0
        this.pgBg2.verticalCenter = 0
        this.addChild(this.pgBg2);

        this.pgBg = new eui.Image("resource/images/loading/loadingArrow.png");
        this.pgBg.horizontalCenter = 0
        this.pgBg.verticalCenter = 0
        this.addChild(this.pgBg);
        EffectUtils.rotationEffect(this.pgBg)

        this.pgBar = new eui.Image("resource/images/loading/textPng2.png");
        this.pgBar.horizontalCenter = 0
        this.pgBar.verticalCenter = 90
        this.addChild(this.pgBar);

        this.textField = new eui.Label();
        this.textField.horizontalCenter = 0
        this.textField.verticalCenter = 130
        this.textField.text = "0%";
        this.textField.size = 20
        this.textField.textColor = 0xffffff
        this.addChild(this.textField);
    }
    private destroy() {
        egret.MainContext.instance.stage.removeEventListener(egret.Event.RESIZE, this.modifyBody, this)
        egret.Tween.removeTweens(this.pgBg)
        this.pg.removeEventListener(egret.Event.COMPLETE, closeLoad, this)
    }
    public modifyBody() {
        this.w = egret.MainContext.instance.stage.stageWidth;
        this.h = egret.MainContext.instance.stage.stageHeight;
        this.width = egret.MainContext.instance.stage.stageWidth;
        this.height = egret.MainContext.instance.stage.stageHeight
    }
    public onProgress(current: number, total: number): void {
        var rate: number = Math.round((current / total) * 100);
        this.textField.text = rate + "%";
    }
}
